package com.modular.scene.bo;

import cn.hutool.core.collection.CollStreamUtil;
import cn.hutool.core.collection.CollUtil;
import com.ToolOpt;
import com.modular.iot.bo.IotData;
import com.modular.iot.bo.IotDataQueryInBo;
import com.modular.scene.bean.SceneDo;
import com.modular.scene.bean.SceneResource;
import lombok.Data;
import ntd.util.modular.things.entity.Device;

import java.util.ArrayList;
import java.util.List;

/**
 * 场景业务对象
 */
@Data
public class SceneBo extends SceneDo {

    /** 场景资源关系 */
    private List<SceneResource> sceneResources = new ArrayList<>();

    public List<IotData> newData() {
        List<String> deviceIds = CollStreamUtil.toList(CollUtil.filter(this.sceneResources, sceneResource ->
                sceneResource.getType().equals("1")), SceneResource::getResourceId);

        List<Device> deviceList = ToolOpt.OPT_T_DEVICE.query().in("id", deviceIds).listBean();

        List<String> codes = CollStreamUtil.toList(deviceList, Device::getCode);

        IotDataQueryInBo iotDataQueryInBo = new IotDataQueryInBo();
        iotDataQueryInBo.setDeviceCodes(codes);
        List<IotData> iotData = ToolOpt.OPT_T_DATA.queryNewData(iotDataQueryInBo);
        return iotData;

    }
}
